home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Environments / PowerMacOberon feb96 / Text / Coco.Tool (.txt) < prev    next >
Encoding:
Oberon Text  |  1994-08-18  |  2.8 KB  |  77 lines  |  [TEXT/.Ob4]

  1. Syntax10.Scn.Fnt
  2. Coco.Compile *
  3. Coco.Compile ~
  4. Coco.Compile ^
  5. Coco.Compile @
  6. (*________________________ usage ________________________*)
  7. Compiler generator Coco. Translates an attributed grammar (syntax-driven
  8. compiler specification) into a recursive descent parser and a scanner.
  9. For a detailed documentation get the PostScript file Coco.Report.ps
  10. via ftp from ftp.inf.ethz.ch, directory /pub/Oberon/Examples/Coco).
  11. Coco.Compile <filename> [options]
  12. The file CR.ATG is an example of an input file to Coco. If the grammar in
  13. the input file has the name X the generated scanner has the name XS.Mod
  14. and the generated parser has the name XP.Mod.
  15. Options:
  16.     /X    generates a cross reference list of all syntax symbols
  17.     /S    generates a list of all terminal start symbols and successors of nonterminal symbols.
  18. Interface of the generated scanner:
  19.     DEFINITION XS;
  20.         IMPORT Texts;
  21.         TYPE
  22.             ErrorProc = PROCEDURE (n: INTEGER; pos: LONGINT);
  23.         VAR
  24.             Error: ErrorProc;
  25.             col, errors, len, line, nextCol, nextLen, nextLine: INTEGER;
  26.             nextPos, pos: LONGINT;
  27.             src: Texts.Text;
  28.         PROCEDURE Reset (t: Texts.Text; pos: LONGINT; errProc: ErrorProc);
  29.         PROCEDURE Get(VAR sym: INTEGER);
  30.         PROCEDURE GetName(pos: LONGINT; len: INTEGER; VAR name: ARRAY OF CHAR);
  31.         PROCEDURE StdErrorProc (n: INTEGER; pos: LONGINT);
  32.     END XS.
  33. Interface of the generated parser:
  34.     DEFINITION XP;
  35.         PROCEDURE Parse;
  36.     END XP.
  37. Example how to use the generated parts;
  38.     Texts.OpenScanner(s, Oberon.Par.Text, Oberon.Par.Pos); Texts.Scan(s);
  39.     IF s.class = Texts.Name THEN
  40.         NEW(text); Texts.Open(text, s.s);
  41.         XS.Reset(text, 0, MyErrorHandler);
  42.         XP.Parse;
  43. Error handling in the generated parser:
  44. The grammar has to contain hints, from which Coco can generate appropriate
  45. error handling. The hints can be placed arbitrarily on the right-hand side of
  46. a production:
  47.     SYNC        Denotes a synchronisation point. At such points symbols are
  48.                     skipped until a symbol is found which is a legal continuation
  49.                     symbol at that point (or eof). SYNC is usually placed at points
  50.                     where particularly "safe" symbols are expected, i.e., symbols
  51.                     that are rarely missing or misspelled.
  52.     WEAK s    s is an arbitrary terminal symbol (e.g., ";") which is considered
  53.                     "weak", because it is frequently missing or misspelled
  54.                     (e.g., a semicolon between statements).
  55. Example:
  56.     Statement =
  57.         SYNC
  58.         ( ident WEAK ":=" Expression
  59.         | "IF" Expression "THEN" StatSeq ["ELSE" StatSeq] "END"
  60.         | "WHILE" Expression "DO" StatSeq "END"
  61.     StatSeq =
  62.         Statement { WEAK ";" Statement}.
  63. (* ________________ files __________________*)
  64. :Text:Coco.Tool
  65. :Source:CR.ATG
  66. :Source:Coco.Mod
  67. :Source:CRS.Mod
  68. :Source:CRP.Mod
  69. :Source:CRT.Mod
  70. :Source:CRX.Mod
  71. :Source:CRA.Mod
  72. :Source:Sets.Mod
  73. :Source:Parser.FRM 
  74. :Source:Scanner.FRM
  75. Compiler.Compile
  76.     Sets.Mod CRS.Mod CRT.Mod CRA.Mod CRX.Mod CRP.Mod Coco.Mod ~
  77.